package com.集合.TreeSet;
/*自然排序Comparable*/
public class Student /*implements Comparable<Student>*/{
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    //重写toString()方法
    public String toString(){
        return "姓名:"+name+", "+"年龄:"+age;
    }

   /* //重写compareTo()方法
    public int compareTo(Student s){
        //return 0;  只输出第一个,因为第一个不需要比较，而其余存储时因为返回0会被认为重复
        //return 1;  存储顺序升序
        //return -1; 存储顺序降序
        //主要条件:按年龄从小到大排序
        //年龄升序
        int num = this.age-s.age;
        //年龄降序
//        int num = s.age-this.age;
        //次要条件：按照姓名的字母顺序排序
        int num1 = num==0?this.name.compareTo(s.name):num;

        return num1;
    }*/
}
